/*
	This file is part of "Ants on the web".

    "Ants on the web" is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Ants on the web" is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with "Ants on the web".  If not, see <http://www.gnu.org/licenses/>.
*/

package org.utc.ia04.antsontheweb.gui.knowledgeBase;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;

public class ChangePageListener implements ActionListener, HyperlinkListener
{
	KnowledgeBaseLearningFrame myFrame;
	
	public ChangePageListener(KnowledgeBaseLearningFrame _frame)
	{
		myFrame = _frame;
	}
	
	public void actionPerformed(ActionEvent evt)
	{
		myFrame.loadPage();
	}

	public void hyperlinkUpdate(HyperlinkEvent event)
	{
		if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
	    {
	      // Modification du champ de saisie
	      myFrame.setAdresse(event.getURL().toString());
	      if(event instanceof HTMLFrameHyperlinkEvent) 
	      {
	        // Evenement spécial en cas d'utilisation de Frame HTML
	        HTMLDocument doc = myFrame.getDocument();
	        doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent)event);
	      }
	      else
	        // Chargement de la page
	    	myFrame.loadPage();
	    }
	}
}
